package com.example.order.service.impl;


import com.example.feign.clients.UserClient;
import com.example.feign.pojo.User;
import com.example.order.mapper.OrderMapper;
import com.example.order.pojo.Orders;
import com.example.order.pojo.vo.OrdersVO;
import com.example.order.service.OrderService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

import javax.annotation.Resource;

/**
 * 分类业务层
 */
@Service
@Slf4j
public class OrderServiceImpl implements OrderService {

    @Resource
    private OrderMapper orderMapper;
    @Resource
    private RestTemplate restTemplate;
    @Resource
    private UserClient userclient;


    @Override
    public OrdersVO getOrder(Long id) {
        OrdersVO ordersVO = new OrdersVO();
        Orders orders = orderMapper.selectById(id);
        BeanUtils.copyProperties(orders,ordersVO);

        // String url = "http://userserver/admin/user/"+orders.getUserId();
        // User user = restTemplate.getForObject(url, User.class);
        User user = userclient.findUserById(orders.getUserId());
        ordersVO.setUser(user);
        return ordersVO ;
    }
}
